package com.hnx.admin.aurora.system.domain.convert.user;


import com.hnx.admin.aurora.system.domain.dto.emp.entity.EmpDTO;
import com.hnx.admin.aurora.system.domain.dto.user.entity.UserDTO;
import com.hnx.admin.aurora.system.domain.vo.user.entity.UserVO;
import org.mapstruct.*;

import java.util.List;
import java.util.Objects;

@Mapper(componentModel = "spring", unmappedSourcePolicy = ReportingPolicy.IGNORE)
public interface UserConvert {
    @Mapping(source = "userId",target = "userId")
    @Mapping(source = "dept",target = "dept")
    @Mapping(source = "roleList",target = "roleList")
    UserVO toVO(UserDTO userDTO);
    @AfterMapping
    default void info(UserDTO userDTO, @MappingTarget UserVO userVO){
        EmpDTO emp = userDTO.getEmp();
        if(Objects.isNull(emp)){
            userVO.setPhonenumber("");
            userVO.setAvatar("");
            userVO.setSex("0");
            userVO.setDeptId("");
            userVO.setEmail("");
        }
        else{
            userVO.setPhonenumber(emp.getPhonenumber());
            userVO.setAvatar(emp.getAvatar());
            userVO.setSex(emp.getSex());
            userVO.setDeptId(emp.getDeptId());
            userVO.setEmail(emp.getEmail());
        }
    }
    List<UserVO> toList(List<UserDTO> list);
}
